Skip to main content

Place Input

Description

<jp-place-input> is a field component with a place lookup functionality.


Attributes

NameRequiredTypeDescription
apiKeystringa unique identifier which is used for authentication of requests associated with usage and billing of Google Maps
mapIdstringunique identifier of a single instance of a Google Map
startingLatitudenumberlatitude to center the map on
startingLongitudenumberlongitude to center the map on
mapTypeOne of the following:
'roadmap', 'satellite',
'hybrid', 'terrain'
an interface that defines the display and usage of map tiles
zoomnumberdetermines the zoom level on the map
labelstringshows at the top of an input
labelType'outside' or 'inside'whether label is inside or outside of the field
namestringname of the form control
idstringunique identifier
inputFocusedbooleandetermines if an input is focused on page load
disabledbooleandetermines if an input is disabled
readonlybooleandetermines if an input is read-only
placeholderstringtemporary text that appears in an
input field before any input is entered
returnedValue'simple' or 'extended'determines if the returned value is dispatched only in a form of address or if it returns coordinates as well as the address
enableMapbooleandetermines if a map is visible
gestureHandlingOne of the following:
'cooperative', 'greedy', 'auto'
determines whether the panning and scrolling behavior on the map is controlled by clicking the zoom controls or by all touch gestures and scroll events
typesstring[]determines type of search results
componentRestrictionobjectused for restricting predictions
valuestringsetter
requiredbooleandetermines if an input is required
requiredValidationMessagestringvalidation message for when component does not satisfy required
resultValidationMessagestringvalidation message for when component cannot find results
validationMessages{[type]: string} where type is stringcompact way of writing validation messages in a single attribute


Dependencies

Permissions

In order for this component to work, Places API, Geocoding API and Google Maps JS SDK (or Google Maps JS API) permissions are required.

Steps on how to enable Places API can be found at:
https://developers.google.com/maps/documentation/javascript/places#GetStarted

Steps on how to enable Geocoding API can be found at:
https://developers.google.com/maps/documentation/javascript/geocoding#GetStarte

Steps on how to enable Google Maps JS SDK or Google Maps JS API can be found at:
https://developers.google.com/maps/documentation/javascript/cloud-setup#enabling-apis



Attributes

In order to use certain attributes you have to implement them in a certain way. The following attributes and the ways to implement them are shown below:

apiKey

In order to be able to use a map, API key needs to be generated. Steps on how to create an API key can be found at:
https://developers.google.com/maps/documentation/javascript/get-api-key#create-api-keys

mapId

In order to be able to use a map, a mapId needs to be generated. Steps on how to create a mapId can be found at:
https://developers.google.com/maps/documentation/get-map-id

types

The attribute is used to reduce search to a more specific result with searching by type of the place. Array can contain up to 5 types and more about types can be found at:
https://developers.google.com/maps/documentation/places/web-service/autocomplete#types

componentRestriction

The attribute is used to restrict search to a more specific prediction. Restrictions are made for specified countries for which the maximum amount is an array of 5 provided countries. More about restrictions can be found at:
https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#ComponentRestrictions



Slots

This component does not have any slots.



Methods

  • getValue
    • returns form field value
  • reportValidity
    • triggers reportValidity


Events

  • value
    • triggers when value of the field changes
  • longitude
    • triggers when value of the field changes if returnedValue is set to 'extended'
  • latitude
    • triggers when value of the field changes if returnedValue is set to 'extended'


Demo

In order to be able to see the demo, api key needs to be filled as the apiKey property of the placeInput object, as well as the mapId property.

Live Editor
// import '@jaspero/web-components/place-input.wc.js';

function placeInput(props){
  let el = useRef(null);
  useEffect(() => {
    const placeInput = document.createElement('jp-place-input')
    placeInput.apiKey = '';
    placeInput.mapId = 'DEMO-MAP-ID';
    //limit the search inside United States
    placeInput.componentRestrictions = {country: 'us'};
    //limit the search by looking only for hospitals
    placeInput.types = ['hospital'];
    placeInput.label = 'Place Input'
    el.current.appendChild(placeInput)
  })
  return (
    <div ref={el}></div>
  )
}

Result
Loading...